package thread;

import java.util.Scanner;

public class demo5 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int x = scanner.nextInt();
        int y = scanner.nextInt();
        long i = 0;
        for(int a = 1;a<=y;a++){
             i = (long) (i + Math.pow(x,a));
        }
        System.out.println(i%1000000007);
    }
}
